home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
kermit.columbia.edu
/
kermit.columbia.edu.tar
/
kermit.columbia.edu
/
newsgroups
/
misc.20000824-20010305
/
000159_news@columbia.edu _Fri Dec 29 13:12:36 2000.msg
< prev
next >
Wrap
Internet Message Format
|
2001-03-05
|
3KB
Return-Path: <news@columbia.edu>
Received: from watsun.cc.columbia.edu (watsun.cc.columbia.edu [128.59.39.2])
by monire.cc.columbia.edu (8.9.3/8.9.3) with ESMTP id NAA18333
for <kermit.misc@cpunix.cc.columbia.edu>; Fri, 29 Dec 2000 13:12:35 -0500 (EST)
Received: from newsmaster.cc.columbia.edu (newsmaster.cc.columbia.edu [128.59.59.30])
by watsun.cc.columbia.edu (8.8.5/8.8.5) with ESMTP id NAA24179
for <kermit.misc@watsun.cc.columbia.edu>; Fri, 29 Dec 2000 13:12:35 -0500 (EST)
Received: (from news@localhost)
by newsmaster.cc.columbia.edu (8.9.3/8.9.3) id NAA08497
for kermit.misc@watsun.cc.columbia.edu; Fri, 29 Dec 2000 13:10:44 -0500 (EST)
X-Authentication-Warning: newsmaster.cc.columbia.edu: news set sender to <news> using -f
From: fdc@columbia.edu (Frank da Cruz)
Subject: Re: Converting struct tm to time_t
Date: 29 Dec 2000 18:10:43 GMT
Organization: Columbia University
Message-ID: <92ik33$89f$1@newsmaster.cc.columbia.edu>
To: kermit.misc@columbia.edu
In article <ylito3uonk.fsf@windlord.stanford.edu>,
Russ Allbery <rra@stanford.edu> wrote:
: INN currently uses [the following], which seems to work fairly well. I'm
: the author of this code; you can consider it to be in the public domain.
: Note that this code requires that time_t be an arithmetic type, which may
: not work properly on some non-UNIX platforms (it could presumably be
: replaced by a long or something).
:
Thanks. Yes, I always knew I could do the day/month/year/time arithmetic
myself, and already do this kind of thing in other parts of the Kermit code,
but not for interfacing with system APIs, e.g. see:
http://www.columbia.edu/kermit/case17.html
As you say, your code does presume a few things about what time_t is:
. An integer (in the mathematical sense), unsigned.
. The number of seconds since 1 Jan 1970 0:00:00.
If that is always true, fine. Of course the whole purpose of having, and
making us use, fabrications like time_t is to hide all that from us. Who
knows what our UNIX vendors will come up with as we approach the 2038 barrier
that will break these assumptions.
Anyway, I suppose it's worth a shot. In the meantime, too bad whoever
thought of mktime() didn't make it do just one thing (in the UNIX spirit),
instead of two things at once, without allowing those things to be done
separately.
Another solution that had occurred to me was to compare the localtime() and
gmtime() results for the same clock time, figure out the GMT/UTC offset, and
deduct it to the target struct tm before passing it to mktime(), but gmtime()
and localtime() are not among the most portable of UNIX APIs, plus I don't
know how consistent their semantics are across platforms, e.g. if you give
them a seconds or minutes field greater than 60 or less than 0, etc.
Thanks again.
- Frank